﻿using JWT.MvcDemo.Help;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JWT.MvcDemo.Controllers
{
    public class UserController : Controller
    {
        private readonly string TimeStamp = ConfigurationManager.AppSettings["TimeStamp"];
        private readonly string LoginKey = ConfigurationManager.AppSettings["LoginKey"];
        // GET: User
        public ActionResult Index()
        {
            ViewBag.Token = Request.Cookies[LoginKey].Value;
            var userinfo = JwtHelp.GetJwtDecode(Request.Cookies[LoginKey].Value);
            ViewBag.UserName = userinfo.UserName;
            return View();
        }
        [HttpPost]
        public ActionResult LoginOut() 
        {
            HttpCookie httpCookie = new HttpCookie(LoginKey);
            httpCookie.Expires = DateTime.Now.AddDays(-1);
            Response.AppendCookie(httpCookie);
            return Json(new {suc=0, msg="退出成功"});
        }
    }
}